# -*- coding: utf-8 -*-
"""
Created on Mon Jun 14 14:42:46 2021

@author: bwh
"""
import random
import copy
class skill:
    def __init__(self,attr,power,pp,hitr,name,typ=[]):
        self.__attr=attr
        self.__power=power
        self.__pp=[pp,pp]
        self.__hitr=hitr
        self.__typ=typ
        self.__name=name
    def getattr(self):
        a=self.__attr
        return a
    def getpower(self):
        a=self.__power
        return a
    def getpp(self):
        a=self.__pp
        return a
    def gettyp(self):
        a=self.__typ
        return a
    def getname(self):
        a=self.__name
        return a
    def gethitr(self):
        a=self.__hitr
        return a
    def tryuse(self):
        if self.__pp[1]>=1:
            return True
        else:
            return False
    def use(self):
        self.__pp[1]+=-1
    def getimfo(self):
        return self.__attr,self.__power,self.__hitr,self.__pp
    def tryhit(self):
        p=self.__hitr/100
        x=random.random()
        if x<=p:
            return True
        else:
            return False

class pkm:
    def __init__(self,attr,rcv,sklis,name,state=[]):
        self.__attr=attr
        self.__rcv=rcv
        self.__sklis=sklis
        self.__state=state
        port=copy.deepcopy(rcv)
        self.__port=port
        self.__hp=[port['hp'],port['hp']]
        self.__name=name
        self.__stlevel={'atk':0,'df':0,'spd':0}
        skilldic={}
        for i in sklis:
            skilldic[i]=copy.deepcopy(skidic[i])
        self.__skilldic=skilldic
    def getattr(self):
        a=self.__attr
        return a
    def chastlevel(self,s,n):
        dic2={'atk':'攻击','df':'防御','spd':'速度'}
        x=self.__stlevel[s]
        def f(p):
            if p<0:
                a=2/(2-p)
            else:
                a=(2+p)/2
            return a
        x1=x+n
        if x1<=6 and x1>=-6:
            p1=f(x+n)/f(x)
            if p1<1:
                print('{}的{}降低了'.format(self.getname(),dic2[s]))
            else:
                print('{}的{}提升了'.format(self.getname(),dic2[s]))
            self.__port[s]=int(self.__port[s]*p1)
            self.__stlevel[s]=x1
    def getport(self):
        a=self.__port
        return a     
    def getskilldic(self):
        a=self.__skilldic
        return a  
    def getname(self):
        a=self.__name
        return a
    def getstate(self):
        a=self.__state
        return a
    def rgetstate(self):
        a=self.__state
        dic={'poisoning':'中毒','parelysis':'麻痹','burn':'灼烧','asleep':'睡眠','disorder':'混乱'}
        if a==[]:
            return ''
        else:
            return '({}状态)'.format(dic[a[0]])
    def movestate(self):
        a=self.__state[0]
        self.removestate(a)
    def changehp(self,value):
        self.__hp[0]+=-value
        if self.__hp[0]>self.__hp[1]:
            return self.__hp[1]
        elif self.__hp[0]>0:
            return self.__hp[0]
        else:
            self.__hp[0]=0
            return 0
    def changeport(self,s):
        a=self.__port
        x=int(0.5*a[s])
        a[s]=x
    def recoverport(self,s):
        a=self.__port
        x=2*a[s]
        a[s]=x
    def show(self,n):
        transdic={'water':'水','fire':'火','glass':'草','electric':'电','poison':'毒','normal':'一般','ice':'冰','fly':'飞行'}
        print('P{}的{}技能'.format(n,self.getname()+self.rgetstate()))
        for i in range(4):
            j=i+1
            k=self.__sklis[i]
            a,b,c,d=self.getskilldic()[k].getimfo()
            a=transdic[a]
            print('{}:{}   属性：{},威力：{},命中率：{},PP:{}/{}'.format(j,k,a,b,c,d[1],d[0]))
    def gethp(self):
        hp=self.__hp[0]
        return hp
    def getskill(self):
        sklis=self.__sklis
        return sklis
    def chastate(self,a,b):
        statedic={'burn':'atk','parelysis':'spd'}
        x=self.__state
        if x==[]:
            self.__state.append(a)
            self.__state.append(b)
            if a in statedic:
                self.changeport(statedic[a])
    def removestate(self,a):
        statedic={'burn':'atk','parelysis':'spd'}
        dic={'poisoning':'中毒','parelysis':'麻痹','burn':'灼烧','asleep':'睡眠','disorder':'混乱'}
        self.__state.clear()
        if a in statedic:
            self.recoverport(statedic[a])
        print('{}的{}状态解除了'.format(self.getname(),dic[a]))
    def constate(self):
        self.__state[1]+=-1
        if self.__state[1]==0:
            self.removestate(self.__state[0])
    def burn(self):
        a=self.__hp[1]
        value=int(a/16)
        hp=self.changehp(value)
        print('{}被灼伤了，受到{}点伤害'.format(self.getname(),value))
        return hp
    def poison(self):
        a=self.__hp[1]
        value=int(a/8)
        hp=self.changehp(value)
        print('{}中毒了，受到{}点伤害'.format(self.getname(),value))
        return hp

class player:
    def __init__(self,bag):
        self.__bag=bag
        self.__wonderLancher=0
        self.__itemlis=['伤药','好伤药','厉害伤药','万灵药','攻击强化','防御强化','速度强化']
        self.__pointlis=[2,4,8,6,3,3,3]
    def wonderLanchercount(self):
        self.__wonderLancher+=1
    def wonderLancheruse(self,n):
        self.__wonderLancher+=-n
    def checkLancheruse(self,n):
        x=self.__wonderLancher
        x1=self.__pointlis[n-1]
        if x-x1>=0:
            return True
        else:
            return False
    def showbag(self):
        print('背包中的宝可梦如下:')
        a=0
        for i in self.__bag:
            a+=1
            hp=i.gethp()
            if hp!=0:
                print('{}.{}(存活) '.format(a,i.getname()),end='')
            else:
                print('{}.{}(阵亡) '.format(a,i.getname()),end='')
        print('\n')
    def getbag(self):
        a=self.__bag
        return a
    def checkdie(self):
        flag=0
        for i in self.getbag():
            if i.gethp()!=0:
                flag=1
        if flag==0:
            return True
        else:
            return False
    def getcount(self):
        a=self.__wonderLancher
        return a
    def showcount(self):
        print('奇迹发射器点数:{}'.format(self.__wonderLancher))
    def showlancher(self):
        print('可用道具：')
        print('1.伤药：2点',end=' ')
        print('2.好伤药：4点',end=' ')
        print('3.厉害伤药：8点',end=' ')
        print('4.万灵药：6点')
        print('5.攻击强化：3点',end=' ')
        print('6.防御强化：3点',end=' ')
        print('7.速度强化：3点')
    def itemuse(self,pkm):
        n=int(input('请选择道具：'))
        while not self.checkLancheruse(n):
            n=int(input('点数不足，请重新选择道具：'))
        self.wonderLancheruse(self.__pointlis[n-1])
        self.showcount()
        if n==1:
            pkm.changehp(-20)
            print('{}恢复了20点hp'.format(pkm.getname()))
        elif n==2:
            pkm.changehp(-50)
            print('{}恢复了50点hp'.format(pkm.getname()))
        elif n==3:
            pkm.changehp(-200)
            print('{}恢复了200点hp'.format(pkm.getname()))
        elif n==4:
            pkm.movestate()
        elif n==5:
            pkm.chastlevel('atk',1)
        elif n==6:
            pkm.chastlevel('df',1)
        elif n==7:
            pkm.chastlevel('spd',1)
                
def solue(pkm,pkmd,skill):
    attr1=pkmd.getattr()
    attr2=skill.getattr()
    p=1
    for i in attr1:
        p*=attrdic[attr2][attrdic[i][0]]
    level=100
    atk=pkm.getport()['atk']
    df=pkmd.getport()['df']
    power=skill.getpower()
    value=int((((2*level+10)/250)*(atk/df)*power+2)*p)
    if power==0:
        value=0
    return value,p 

def aichoice(x,pkm,pkmd,n):
    if x==0:
        pp=0
        while pp==0:
            a=random.randint(1,4)
            skill=skidic[pkm.getskill()[a-1]]
            pp=skill.getpp()[1]
    else:
        s=0
        a=0
        for i in range(1,5):
            skill=skidic[pkm.getskill()[i-1]]
            hit=skill.gethitr()
            s1=hit*solue(pkm,pkmd,skill)[0]
            pp=skill.getpp()[1]
            if s1>s and pp!=0:
                s=s1
                a=i                  
    return a

def spdcom(pkm,pkmd):
    spd1=pkm.getport()['spd']
    spd2=pkmd.getport()['spd']
    if spd1>spd2:
        return True
    else:
        return False
    
def choice(n,pkm,pkmd,isai,mod):
    if isai==0:
        x=int(input('P{}选择技能：'.format(n)))
        skill=pkm.getskilldic()[pkm.getskill()[x-1]]
        pp=skill.getpp()[1]
        while pp==0:
            print('该技能pp值已耗尽')
            x=int(input('P{}重新选择技能：'.format(n))) 
            skill=pkm.getskilldic()[pkm.getskill()[x-1]]
            pp=skill.getpp()[1]
    else:
        x=aichoice(mod,pkm,pkmd,n)
    skill=pkm.getskilldic()[pkm.getskill()[x-1]]
    return skill

def dameff(skill,pkm,pkmd):
    s,p=solue(pkm,pkmd,skill)
    na=skill.getname()
    p2=random.random()
    if s>0:
        if p2>=0.7:
            if p==1:
                print('{}使用了{}攻击{},造成了{}点伤害'.format(pkm.getname(),na,pkmd.getname(),s))
            elif p<=0.5:
                print('{}使用了{}攻击{},造成了{}点伤害,效果不佳'.format(pkm.getname(),na,pkmd.getname(),s))
            else:
                print('{}使用了{}攻击{},造成了{}点伤害,效果拔群'.format(pkm.getname(),na,pkmd.getname(),s))
        else:
            s=int(1.5*s)
            if p==1:
                print('{}使用了{}攻击{},击中要害,造成了{}点伤害'.format(pkm.getname(),na,pkmd.getname(),s))
            elif p<=0.5:
                print('{}使用了{}攻击{},击中要害,造成了{}点伤害,效果不佳'.format(pkm.getname(),na,pkmd.getname(),s))
            else:
                print('{}使用了{}攻击{},击中要害,造成了{}点伤害,效果拔群'.format(pkm.getname(),na,pkmd.getname(),s))
        pkmd.changehp(s)
    else:
        print('{}使用了{}攻击{}'.format(pkm.getname(),na,pkmd.getname()))

def checkcontrol(pkm):
    a=pkm.getstate()
    if a==[]:
        return False
    else:
        state=a[0]
        p1=random.randint(1,3)
        if state=='asleep':
            print('{}睡着了,无法使用技能'.format(pkm.getname()))
            pkm.constate()
            return True
        elif state=='disorder' and p1==1:
            value,p=solue(pkm,pkm,disorder)
            pkm.changehp(value)
            print('{}混乱了,对自己造成{}点伤害'.format(pkm.getname(),value))
            pkm.constate()
            return True
        elif state=='parelysis':
            p1=random.randint(1, 4)
            if p1==1:
                print('{}麻痹了,无法使用技能'.format(pkm.getname()))
                pkm.constate()
                return True
        else:
            pkm.constate()
            return False

                       
def checkhurt(pkm):
    a=pkm.getstate()
    if a!=[]:
        state=a[0]
        if state=='burn':
            pkm.constate()
            pkm.burn()
        elif state=='poisoning':
            pkm.constate()
            pkm.poison()
     

def skilluse(skill,pkm,pkmd,n):
    dic={'poisoning':'中毒','parelysis':'麻痹','burn':'灼烧','asleep':'睡眠','disorder':'混乱'}
    dic2={'atk':'攻击','df':'防御','spd':'速度'}
    skill.use()
    def f2(i,pkms):
        if i=='burn' or i=='parelysis' or i=='poisoning':
            pkms.chastate(i, -1)
            print('{}进入了{}状态'.format(pkms.getname(),dic[i]))
        elif i=='asleep':
            x=random.randint(1,3)
            pkms.chastate(i, x)
            y=str(x)
            print('{}进入了睡眠状态,持续{}回合'.format(pkms.getname(),y))
        elif i=='disorder':
            x=random.randint(1,4)
            pkms.chastate(i, x)
            y=str(x)
            print('{}进入了混乱状态,持续{}回合'.format(pkms.getname(),y))
    if skill.tryhit():
        dameff(skill,pkm,pkmd)
        if skill.gettyp()!=[]:
            for i in skill.gettyp():
                lis=list(i.split())
                x=random.random()
                b=float(lis[-1])
                if x<=b:
                    if lis[1]=='self':
                        pkms=pkm
                    elif lis[1]=='ops':
                        pkms=pkmd                
                    if lis[0] in dic:
                        f2(lis[0],pkms)
                    elif lis[0] in dic2:
                        pkms.chastlevel(lis[0],int(lis[2]))
    else:
        print('{}使用了{}攻击{},被躲开了'.format(pkm.getname(),skill.getname(),pkmd.getname()))
    
def checkresult(player,pkm,isai,playerd,pkmd,isaid):
    hp1=pkm.gethp()
    hp2=pkmd.gethp()
    if hp1==0 and hp2==0:
        print('同归于尽')
    elif hp1==0:
        print('P1的{}阵亡'.format(pkm.getname()))
    elif hp2==0:
        print('P2的{}阵亡'.format(pkmd.getname()))
    if player.checkdie() and playerd.checkdie():
        print('平局')
        return True
    elif player.checkdie():
        print('P2获胜')
        return True
    elif playerd.checkdie():
        print('P1获胜')
        return True
    else:
        return False
    
def printhp(pkm,pkmd):
    hp1=pkm.gethp()
    hp2=pkmd.gethp()
    print('P1的{}的HP:{}'.format(pkm.getname(),hp1))
    print('P2的{}的HP:{}'.format(pkmd.getname(),hp2))

def pkmchoice(player,isai,pkmd):
    if isai==0:
        player.showbag()
        s1=input(('请选择即将上场的宝可梦：'))
        s1=int(s1)-1
        while player.getbag()[s1].gethp()==0:
            s1=int(input(('该宝可梦已阵亡，请重新选择即将上场的宝可梦：')))-1
        pkms1=player.getbag()[s1]
        print('{}上场'.format(pkms1.getname()))
        return pkms1
    else:
        for pk in player.getbag():
            if pk.gethp()!=0:
                attr1=pkmd.getattr()
                attr2=pk.getattr()
                p0=0
                p=1
                for i in attr1:
                    for j in attr2:
                        p*=attrdic[j][attrdic[i][0]]
                if p>p0:
                    p0=p
                    pkms1=pk
        print('{}上场'.format(pkms1.getname()))
        return pkms1
    
    
    
       
strike=skill('normal',40,35,100,'冲撞')
seedBomb=skill('glass',80,15,100,'种子炸弹')
scratch=skill('normal',40,35,100,'抓')
conguetry=skill('normal',0,20,100,'撒娇',['atk ops -1 1'])
jetFame=skill('fire',90,15,100,'喷射火焰',['burn ops 0.3'])
purgatory=skill('fire',100,15,50,'炼狱',['burn ops 1'])
ghostFace=skill('normal',0,10,100,'鬼面',['spd ops -1 1'])
poisonPowder=skill('poison',0,35,75,'毒粉',['poisoning ops 1'])
hypnosisPowder=skill('poison',0,15,75,'催眠粉',['asleep ops 1'])
waterCannon=skill('water',110,5,80,'水炮')
waterWave=skill('water',60,20,100,'水之波动',['disorder ops 0.3'])
wagTail=skill('normal',0,30,100,'摇尾巴',['df ops -1 1'])
ironWall=skill('normal',0,15,100,'铁壁',['df self 1 1'])
swift=skill('normal',0,30,100,'高速移动',['spd self 2 1'])
lacvolt=skill('electric',90,10,100,'十万伏特',['parelysis ops 0.3'])
beat=skill('normal',80,20,75,'摔打')
dragonDance=skill('normal',0,15,100,'龙之舞',['spd self 1 1','atk self 1 1'])
iceWind=skill('ice',55,15,95,'冰冻之风',['spd ops -1 1'])
storm=skill('fly',110,10,70,'暴风',['disorder ops 0.3'])
stare=skill('normal',0,30,100,'瞪眼',['df ops -1 1'])
disorder=skill('normal',40,999,100,'混乱')
supersonic=skill('normal',0,20,55,'超音波',['disorder ops 1'])
airSlash=skill('fly',75,15,95,'空气斩')
sludgeBomb=skill('poison',90,10,100,'污泥炸弹',['poisoning ops 0.3'])
swordsDance=skill('normal',0,20,100,'剑舞',['atk self 2 1'])
leafBlade=skill('glass',90,15,100,'叶刃')
peck=skill('fly',35,35,100,'啄')
defenseCurl=skill('normal',0,40,100,'变圆',['df self 1 1'])
bodySlam=skill('normal',85,10,100,'泰山压顶',['parelysis ops 0.3'])
hammerArm=skill('normal',100,10,90,'臂锤',['spd self -1 1'])
Screech=skill('normal',0,40,85,'刺耳声',['df ops -2 1'])

skidic={'冲撞':strike,'种子炸弹':seedBomb,'抓':scratch,'撒娇':conguetry,'喷射火焰':jetFame,\
        '炼狱':purgatory,'鬼面':ghostFace,'毒粉':poisonPowder,'催眠粉':hypnosisPowder,'瞪眼':stare,\
        '水炮':waterCannon,'水之波动': waterWave,'摇尾巴':wagTail,'铁壁':ironWall,'高速移动':swift,\
        '十万伏特':lacvolt,'摔打':beat,'龙之舞':dragonDance,'冰冻之风':iceWind,'暴风':storm,\
        '混乱':disorder,'超音波':supersonic,'空气斩':airSlash,'污泥炸弹':sludgeBomb,'剑舞':swordsDance,\
        '叶刃':leafBlade,'啄':peck,'变圆':defenseCurl,'泰山压顶':bodySlam,'臂锤':hammerArm,'刺耳声':Screech}
Bulbasaur=pkm(['glass','poison'],{'hp':294,'atk':256,'df':216,'spd':207},['冲撞','催眠粉','种子炸弹','毒粉'],'妙蛙种子')
Charmander=pkm(['fire'],{'hp':282,'atk':263,'df':203,'spd':251},['抓','喷射火焰','鬼面','炼狱'],'小火龙')
Squirtle=pkm(['water'],{'hp':292,'atk':254,'df':292,'spd':203},['水炮','水之波动','摇尾巴','铁壁'],'杰尼龟')
Pikachu=pkm(['electric'],{'hp':274,'atk':279,'df':196,'spd':306},['高速移动','十万伏特','摔打','撒娇'],'皮卡丘')
Gyarados=pkm(['water','fly'],{'hp':300,'atk':338,'df':194,'spd':230},['龙之舞','冰冻之风','暴风','瞪眼'],'暴鲤龙')
Zubat=pkm(['fly','poison'],{'hp':284,'atk':247,'df':184,'spd':229},['超音波','空气斩','污泥炸弹','高速移动'],'超音蝠')
Farfetchd=pkm(['normal','poison'],{'hp':308,'atk':306,'df':229,'spd':240},['啄','剑舞','瞪眼','叶刃'],'大葱鸭')
Snorlax=pkm(['normal'],{'hp':467,'atk':273,'df':152,'spd':174},['变圆','泰山压顶','臂锤','刺耳声'],'卡比兽')

attrdic={'water':[1,0.5,2,0.5,1,1,1,1,1],'fire':[2,0.5,0.5,2,1,1,1,2,1],'glass':[3,2,0.5,0.5,1,0.5,1,0.5,1],'electric':[4,2,1,0.5,0.5,1,1,2,1],\
         'poison':[5,1,1,2,1,0.5,1,1,1],'normal':[6,1,1,1,1,1,1,1,1],'ice':[7,0.5,0.5,2,1,1,1,0.5,2],'fly':[8,1,1,2,0.5,1,1,1,1]}
pkmdic={'妙蛙种子':Bulbasaur,'小火龙':Charmander,'杰尼龟':Squirtle,'皮卡丘':Pikachu,'暴鲤龙':Gyarados,'超音蝠':Zubat,'大葱鸭':Farfetchd,'卡比兽':Snorlax}
pkmlis='妙蛙种子','小火龙','杰尼龟','皮卡丘','暴鲤龙','超音蝠','大葱鸭','卡比兽'

isai1=0
isai2=0
mod=0
print('20377113 柏文浩')
ch1=input('请选择P1为玩家还是AI:')
ch2=input('请选择P2为玩家还是AI:')
if ch1!='玩家' or ch1!='玩家':
    mod=int(input('请选择AI模式 (0：随机模式，1：伤害最优模式):\n'))
print('可选择的宝可梦如下')
print(' '.join(pkmlis))
if ch1=='玩家':
    pkm1p=input('请P1选择宝可梦:')
    lis2=[]
    for i in pkm1p.split():
        lis2.append(copy.deepcopy(pkmdic[i]))
    player1=player(lis2)
else:
    lis1=[]
    lis2=[]
    for i in range(3):
        x=random.randint(0+i,7+i)-i
        pkm1p=pkmlis[x]
        lis1.append(pkm1p)
        pkm1=copy.deepcopy(pkmdic[pkm1p])
        lis2.append(pkm1)
    player1=player(lis2)
    print('P1的AI选择:',end='')
    print(' '.join(lis1))
    isai1=1
if ch2=='玩家':
    pkm2p=input('请P2选择宝可梦:')
    lis2=[]
    for i in pkm2p.split():
        lis2.append(copy.deepcopy(pkmdic[i]))
        player2=player(lis2)
else:
    lis1=[]
    lis2=[]
    for i in range(3):
        x=random.randint(0+i,7+i)-i
        pkm2p=pkmlis[x]
        lis1.append(pkm2p)
        pkm2=copy.deepcopy(pkmdic[pkm2p])
        lis2.append(pkm2)
    player2=player(lis2)
    print('P2的AI选择:',end='')
    print(' '.join(lis1))
    isai2=1
rou=0
pkm1=player1.getbag()[0]
pkm2=player2.getbag()[0]
printhp(pkm1,pkm2)

while True:
    rou+=1
    useflag1=0
    useflag2=0
    player1.wonderLanchercount()
    player2.wonderLanchercount()
    print('Round{}'.format(rou))
    if isai1==0:
        s=input('P1是否选择切换宝可梦：')
        if s=='是':
            useflag1=1
            pkm1=pkmchoice(player1,isai1,pkm2)
    if isai2==0:
        s=input('P2是否选择切换宝可梦：')
        if s=='是':
            useflag2=1
            pkm1=pkmchoice(player2,isai2,pkm1)   
    if spdcom(pkm1,pkm2):
        printhp(pkm1,pkm2)
        if not checkcontrol(pkm1) and useflag1==0:
            pkm1.show(1)
            player1.showcount()
            if player1.getcount()>=2 and isai1==0:
                alt=input('P1选择是否使用奇迹发射器：')
                if alt=='是':
                    player1.showlancher()
                    player1.itemuse(pkm1)
                    useflag1=1
            if useflag1==0:
                skill1=choice(1,pkm1,pkm2,isai1,mod)
                skilluse(skill1,pkm1,pkm2,1)
            if not checkresult(player1,pkm1,isai1,player2,pkm2,isai2):
                if pkm1.gethp()==0:
                    pkm1=pkmchoice(player1,isai1,pkm2)
                    useflag1=1
                if pkm2.gethp()==0:            
                    pkm2=pkmchoice(player2,isai2,pkm1)
                    useflag2=1
            else:
                break
        printhp(pkm1,pkm2)
        if not checkcontrol(pkm2) and useflag2==0:
            pkm2.show(2)
            player2.showcount()
            if player2.getcount()>=2 and isai2==0:
                alt=input('P2选择是否使用奇迹发射器：')
                if alt=='是':
                    player2.showlancher()
                    player2.itemuse(pkm2)
                    useflag2=1
            if useflag2==0:
                skill2=choice(2,pkm2,pkm1,isai2,mod)        
                skilluse(skill2,pkm2,pkm1,2)
            if not checkresult(player1,pkm1,isai1,player2,pkm2,isai2):
                if pkm1.gethp()==0:
                    pkm1=pkmchoice(player1,isai1,pkm2)
                if pkm2.gethp()==0:            
                    pkm2=pkmchoice(player2,isai2,pkm1)
            else:
                break
        checkhurt(pkm1)
        checkhurt(pkm2)
        if not checkresult(player1,pkm1,isai1,player2,pkm2,isai2):
                if pkm1.gethp()==0:
                    pkm1=pkmchoice(player1,isai1,pkm2)
                if pkm2.gethp()==0:            
                    pkm2=pkmchoice(player2,isai2,pkm1)
        else:
            break  
    else:
        printhp(pkm1,pkm2)
        if not checkcontrol(pkm2):
            pkm2.show(2)
            player2.showcount()
            if player2.getcount()>=2 and isai2==0:
                alt=input('P2选择是否使用奇迹发射器：')
                if alt=='是':
                    player2.showlancher()
                    player2.itemuse(pkm2)
                    useflag2=1
            if useflag2==0:
                skill2=choice(2,pkm2,pkm1,isai2,mod)        
                skilluse(skill2,pkm2,pkm1,2)
            if not checkresult(player1,pkm1,isai1,player2,pkm2,isai2):
                if pkm1.gethp()==0:
                    pkm1=pkmchoice(player1,isai1,pkm2)
                if pkm2.gethp()==0:            
                    pkm2=pkmchoice(player2,isai2,pkm1)
            else:
                break
        printhp(pkm1,pkm2)
        if not checkcontrol(pkm1):
            pkm1.show(1)
            player1.showcount()
            if player1.getcount()>=2 and isai1==0:
                alt=input('P1选择是否使用奇迹发射器：')
                if alt=='是':
                    player1.showlancher()
                    player1.itemuse(pkm1)
                    useflag1=1
            if useflag1==0:
                skill1=choice(1,pkm1,pkm2,isai1,mod)
                skilluse(skill1,pkm1,pkm2,1)
            if not checkresult(player1,pkm1,isai1,player2,pkm2,isai2):
                if pkm1.gethp()==0:
                    pkm1=pkmchoice(player1,isai1,pkm2)
                if pkm2.gethp()==0:            
                    pkm2=pkmchoice(player2,isai2,pkm1)
            else:
                break
        checkhurt(pkm1)
        checkhurt(pkm2)
        if not checkresult(player1,pkm1,isai1,player2,pkm2,isai2):
                if pkm1.gethp()==0:
                    pkm1=pkmchoice(player1,isai1,pkm2)
                if pkm2.gethp()==0:            
                    pkm2=pkmchoice(player2,isai2,pkm1)
        else:
            break   
     

    

        
        
